"""配置加载模块，用于加载和管理应用配置"""

import os
import yaml

from .utils.display import display


class ConfigLoader:
    """加载和管理应用配置"""

    def load(self):
        """
        功能：从YAML文件加载配置
        :return: 包含配置的字典
        """
        config_path = "config.yaml"
        default_config = {"default_model": None, "system_reserved_cores": 1}

        if os.path.exists(config_path):
            try:
                with open(config_path, "r", encoding="utf-8") as f:
                    config = yaml.safe_load(f)
                    return {**default_config, **config}
            except (IOError, yaml.YAMLError) as e:
                display(f"⚠️ 配置文件加载错误: {e}, 使用默认配置")

        return default_config

    def print_config(self, config):
        """
        功能：打印当前的配置信息
        :param config: 要打印的配置字典
        :return: 无
        """
        display("📋📋 当前配置信息:")
        for key, value in config.items():
            display(f"  • {key}: {value}")
